<?php
/**
 * 路由限流器达到峰值时，回调的通知函数
*/

namespace houze\lifecycle;

class limit_route_check
{
    /**
     * 接受回调处理
    */
    public function run($server, $fd, $server_type, $route, $data) {
        $msg = $route.' 已被限制，'.$data['time'].'s 内，只允许访问'.$data['peak'].'次！';
        switch ($server_type) {
            case 'http':
                $obj = new \houze\controller\Http();
                $obj->fetch($msg);
            break;
            case 'websocket':
                $obj = new \houze\controller\WebSocket();
                $obj->fetch('limit_error', 'error', $msg);
            break;
            case 'rpc':
                $ServerCurrency = new \houze\rpc\ServerCurrency();
                $ServerCurrency->returnJson($server,  $fd, '200', 'RPC Route LIMIT', $msg);
            break;
        }
        return true;
    }
}